using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Microformats.Entities;
using System.IO;
using Microformats.Readers;
using Microformats.ConfigurationSections;
using System.Configuration;

namespace MicroformatUnitTests
{
    [TestFixture]
    public class MicroformatReaderTest
    {
        [Test]
        [Ignore]
        [ExpectedException(typeof(ConfigurationErrorsException))]
        public void StreamReaderConstructionWithNoConfiguration()
        {
            MicroformatConfigSection mcs = (MicroformatConfigSection)ConfigurationManager.GetSection("MicroformatsSection");


            mcs.SectionInformation.SetRawXml("");
            MicroformatReader mr = new MicroformatReader(new MemoryStream(),InputSourceType.Html);
            ConfigurationManager.RefreshSection("MicroformatsSection");

            Assert.IsNotNull(mr);
        }

        [Test]
       
        public void StreamReaderConstruction()
        {

            MicroformatReader mr = new MicroformatReader(new MemoryStream(), InputSourceType.Html);
            

            Assert.IsNotNull(mr);
        }

        [Test]
        public void TextReaderConstruction()
        {
            MicroformatReader mr = new MicroformatReader(new StringReader("<html><body></body></html>"), InputSourceType.Html);

            Assert.IsNotNull(mr);
            Assert.IsNotNull(mr.Reader);
            //Assert.IsInstanceOfType(mr.Reader);  Cannot be determined here because the type is hidden from all other assemblies.
        }


        [Test]
        public void TextReaderNoFormatsInTextReader()
        {
            MicroformatReader mr = new MicroformatReader(new StringReader("<html><body></body></html>"), InputSourceType.Html);
            Assert.IsNull(mr.Read());
           
        }

        [Test]
        public void TextReaderNoFormatsInStream()
        {
            byte[] b = Encoding.Default.GetBytes("<html><body></body></html>");
            MicroformatReader mr = new MicroformatReader(new MemoryStream(b), InputSourceType.Html);
            Assert.IsNull(mr.Read());

        }

    }
}
